package com.ruoyi.web.controller.commissionrule;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.commissionrule.domain.AmCommissionRule;
import com.ruoyi.commissionrule.domain.vo.AmCommissionRuleVo;
import com.ruoyi.commissionrule.service.IAmCommissionRuleService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 分佣机制管理Controller
 * 
 * @author ruoyi
 * @date 2020-07-28
 */
@RestController
@RequestMapping("/commissionrule/commissionrule")
@Api(description = "分佣机制管理")
public class  AmCommissionRuleController extends BaseController
{
    @Autowired
    private IAmCommissionRuleService amCommissionRuleService;

    /**
     * 查询分佣机制管理列表
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:list')")
    @GetMapping("/list")
    @ApiOperation("查询分佣机制管理列表")
    public TableDataInfo list(AmCommissionRule amCommissionRule)
    {
        startPage();
        List<AmCommissionRule> list = amCommissionRuleService.selectAmCommissionRuleList(amCommissionRule);
        return getDataTable(list);
    }

    /**
     * 导出分佣机制管理列表
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:export')")
    @Log(title = "分佣机制管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出分佣机制管理列表")
    public AjaxResult export(AmCommissionRule amCommissionRule)
    {
        List<AmCommissionRule> list = amCommissionRuleService.selectAmCommissionRuleList(amCommissionRule);
        ExcelUtil<AmCommissionRule> util = new ExcelUtil<AmCommissionRule>(AmCommissionRule.class);
        return util.exportExcel(list, "commissionrule");
    }

    /**
     * 获取分佣机制管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取分佣机制管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amCommissionRuleService.selectAmCommissionRuleById(id));
    }

    /**
     * 新增分佣机制管理
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:add')")
    @Log(title = "分佣机制管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("分佣机制管理")
    public AjaxResult add(@RequestBody String data)

    {
        AmCommissionRuleVo amCommissionRule = JSONObject.parseObject(data, AmCommissionRuleVo.class);
        return toAjax(amCommissionRuleService.insertAmCommissionRule(amCommissionRule));
    }

    /**
     * 修改分佣机制管理
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:edit')")
    @Log(title = "分佣机制管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("分佣机制管理")
    public AjaxResult edit(@RequestBody String data)
    {
        AmCommissionRuleVo amCommissionRule = JSONObject.parseObject(data, AmCommissionRuleVo.class);
        return toAjax(amCommissionRuleService.updateAmCommissionRule(amCommissionRule));
    }

    /**
     * 删除分佣机制管理
     */
    @PreAuthorize("@ss.hasPermi('commissionrule:commissionrule:remove')")
    @Log(title = "分佣机制管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("分佣机制管理")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amCommissionRuleService.deleteAmCommissionRuleByIds(ids));
    }
}
